<template>
  <el-dialog
    :title="'销售订单选择'"
    :close-on-click-modal="false"
    :visible.sync="innerVisible"
    width="100%"
    append-to-body>
  <div class="mod-config">
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%; margin-top: 20px">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column
        prop="saleOrderName"
        header-align="center"
        align="center"
        width="250px"
        label="销售订单">
      </el-table-column>

      <el-table-column
        prop="saleDate"
        header-align="center"
        align="center"
        label="销售日期">
      </el-table-column>
      <el-table-column
        prop="saleTotalAmount"
        header-align="center"
        align="center"
        label="单据金额">
      </el-table-column>
      <el-table-column
        prop="deposit"
        header-align="center"
        align="center"
        label="定金">
      </el-table-column>
      <el-table-column
        prop="writtenOffAmount"
        header-align="center"
        align="center"
        label="已核销金额">
      </el-table-column>
      <el-table-column
        prop="remainAmount"
        header-align="center"
        align="center"
        label="未核销金额">
      </el-table-column>
      <el-table-column
        prop="writtenOffNum"
        header-align="center"
        align="center"
        label="已核销次数">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <span slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取消</el-button>
      <el-button type="primary" @click="selectedForOrders()">确定</el-button>
    </span>
  </div>
  </el-dialog>
</template>

<script>
  import Utils from '../../../utils/event.js'

export default {
    data () {
      return {
        dataForm: {
          headerId: 0,
          key: ''
        },
        formDto: {
          receiptDetailList: [],
          deleteReceiptDetailList: []
        },
        dataList: [],
        delList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        saleOrderSelectVisible: false,
        innerVisible: false,
        thisWrittenOffAmount: 0,
        clientId: ''
      }
    },
    methods: {
      // 获取数据列表
      init (id) {
        this.dataForm.headerId = id
        this.innerVisible = true
        this.dataListLoading = true
        this.delList = []
        this.$http({
          url: this.$http.adornUrl('/sales/orderheader/listSaleOrdersByClientId'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'clientId': id
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },

      selectedForOrders () {
        this.innerVisible = false
        Utils.$emit('demo', this.dataListSelections)
      }
    }
  }
</script>
